package com.heyqing.topic.RemoveStars_2390;

/**
 * ClassName:RemoveStars
 * Package:com.heyqing.topic.RemoveStars_2390
 * Description:
 *
 * @Date:2024/9/14
 * @Author:Heyqing
 */
public class RemoveStars {
    public String removeStars(String s) {
        StringBuffer sb = new StringBuffer();
        int flag = 0;
        for (int i = s.length() - 1; i >= 0; i--) {
            if (s.charAt(i) == '*') {
                flag++;
                continue;
            }
            if (flag > 0) {
                flag--;
                continue;
            }
            if (flag == 0) {
                sb.append(s.charAt(i));
            }
        }
        return sb.reverse().toString();
    }

    public static void start() {
        String s = "0123**678*x";
        RemoveStars removeStars = new RemoveStars();
        String res = removeStars.removeStars(s);
        System.out.println("answer: 0167x");
        System.out.println("res:    " + res);
    }
}
